package Action;





import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import Form.LoginUserForm;
import Model.user;
import Service.userService;
/**
 * 登录动作类
 * @author MacBook
 *
 */
public class LoginAction extends ActionSupport implements ModelDriven<LoginUserForm>{
	private LoginUserForm userform = new LoginUserForm();
	
	public LoginUserForm getUserform() {
		return userform;
	}

	public void setUserform(LoginUserForm userform) {
		this.userform = userform;
	}

	@Override
	public LoginUserForm getModel() {
		// TODO Auto-generated method stub
		return userform;
	}
	//Action控制器方法
	public String execute(){
		userService login = new userService();
		user u = login.LoginService(userform.getUsername(), userform.getPassword());
		if(u == null)
			return ERROR;
		else{
			ActionContext.getContext().getSession().put("user", u);
			//此处验证出现过问题
			if(u.getPower() .equals("normal"))
				return "normal";
			else
				return "admin";
		}
	}

	
}
